package com.jifeng.sterilizer.service.impl;

import com.jifeng.sterilizer.utils.PageUtils;
import com.jifeng.sterilizer.utils.Query;
import com.jifeng.sterilizer.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jifeng.sterilizer.dao.VwPhoneUserDao;
import com.jifeng.sterilizer.entity.VwPhoneUserEntity;
import com.jifeng.sterilizer.service.VwPhoneUserService;


@Service("vwPhoneUserService")
@Slf4j
public class VwPhoneUserServiceImpl extends ServiceImpl<VwPhoneUserDao, VwPhoneUserEntity> implements VwPhoneUserService {

    /**
     * @param params {"farm":"","name":"","idcard":"","account":"","status":0,"curPage":1,"limit":10}
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        try {
            QueryWrapper<VwPhoneUserEntity> queryWrapper = new QueryWrapper<>();
            Object farm = params.get("farm");
            Object name = params.get("name");
            Object idcard = params.get("idcard");
            Object account = params.get("account");
            Object status = params.get("status");
            if (!farm.equals("")) {
                queryWrapper.like("farm", farm);
            }
            if (!name.equals("")) {
                queryWrapper.like("name", name);
            }
            if (!idcard.equals("")) {
                queryWrapper.eq("idcard", idcard);
            }
            if (!account.equals("")) {
                queryWrapper.eq("account", account);
            }
            if (!status.equals("")) {
                queryWrapper.eq("status", status);
            }
            IPage<VwPhoneUserEntity> page = this.page(
                    new Query<VwPhoneUserEntity>().getPage(params),
                    queryWrapper
            );

            return new PageUtils(page);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("方法：{}，错误信息：{}", "手机端用户账号管理列表 PC", e.getMessage());
            return null;
        }
    }

}